import uuid

from django.db import models
from music.models import MusicList
from post.models import PostList
# Create your models here.

class MusicFavorite(models.Model):
    id = models.CharField(max_length=128, primary_key=True, verbose_name='Id')
    user = models.ForeignKey('user.User', db_column='user', on_delete=models.CASCADE, verbose_name='用户')
    music = models.ForeignKey('music.MusicList', db_column='music', on_delete=models.CASCADE, verbose_name='音乐')
    collect_time = models.DateTimeField(auto_now_add=True, verbose_name='收藏时间')

    class Meta():
        db_table = 'music_favorite'
        managed = True

    # def __str__(self):
    #     music_name = MusicList.objects.filter(self.music.id)
    #     return music_name

    def save(self, *args, **kwargs):
        if not self.id:
            self.id = uuid.uuid4()
        super(MusicFavorite, self).save()


class PostFavorite(models.Model):
    id = models.CharField(max_length=128, primary_key=True, verbose_name='Id')
    user = models.ForeignKey('user.User', db_column='user', on_delete=models.CASCADE, verbose_name='用户')
    post = models.ForeignKey('post.PostList', db_column='post', on_delete=models.CASCADE, verbose_name='主题')
    collect_time = models.DateTimeField(auto_now_add=True, verbose_name='收藏时间')

    class Meta:
        db_table = 'post_favorite'
        managed = True

    # def __str__(self):
    #     post_title = PostList.objects.filter(self.post.id)
    #     return post_title

    def save(self, *args, **kwargs):
        if not self.id:
            self.id = uuid.uuid4()
        super(PostFavorite, self).save()